package com.baseLearn.learn.designPatterns.proxy.jdkDynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class LawyerFactory {

    private Person person;

    //维护一个目标对象(被代理对象）
    public LawyerFactory help(Person person) {
        this.person = person;
        return this;
    }

    //给目标对象生成代理对象
    public Object getProxyInstant() {
        return Proxy.newProxyInstance(person.getClass().getClassLoader(), person.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("111");
                Object object = method.invoke(person, args);
                System.out.println("2222");
                return object;

            }
        });
    }

}
